package org.zoomdev.zoom.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;

public final class StatementUtils {

    static final PreparedStatement prepareStatement(
            Connection connection,
            String sql,
            List<Object> values,
            boolean output) throws SQLException {
        if (output) {
            RecordSqlUtils.logSql(sql, values);
        }

        PreparedStatement ps = connection.prepareStatement(sql);
        prepareStatement(ps, values);
        return ps;
    }


    static final void prepareStatement(PreparedStatement ps, List<Object> values) throws SQLException {
        for (int index = 1, c = values.size(); index <= c; ++index) {
            ps.setObject(index, values.get(index - 1));
        }
    }

}
